﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.OracleClient;
using DBUtility;
using System.Data;

namespace DataAccess.CustomerDAC
{
    public class CustomerDAC
    {
        #region TB_USER
        public Model.TB_USER GetModel(string userName, string pwd)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select NID,CUSERNAME,CNICKNAME,CPASSWORD,NTYPE from TB_USER ");
            strSql.Append(" where CUSERNAME=:CUSERNAME and CPASSWORD=:CPASSWORD");
            OracleParameter[] parameters = {
					new OracleParameter(":CUSERNAME", OracleType.NVarChar),
        			new OracleParameter(":CPASSWORD", OracleType.NVarChar)};

            parameters[0].Value = userName;
            parameters[1].Value = pwd;

            Model.TB_USER model = new Model.TB_USER();
            DataSet ds = DbHelperOra.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["NID"] != null && ds.Tables[0].Rows[0]["NID"].ToString() != "")
                {
                    model.NID = decimal.Parse(ds.Tables[0].Rows[0]["NID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["CUSERNAME"] != null && ds.Tables[0].Rows[0]["CUSERNAME"].ToString() != "")
                {
                    model.CUSERNAME = ds.Tables[0].Rows[0]["CUSERNAME"].ToString();
                }
                if (ds.Tables[0].Rows[0]["CNICKNAME"] != null && ds.Tables[0].Rows[0]["CNICKNAME"].ToString() != "")
                {
                    model.CNICKNAME = ds.Tables[0].Rows[0]["CNICKNAME"].ToString();
                }
                if (ds.Tables[0].Rows[0]["CPASSWORD"] != null && ds.Tables[0].Rows[0]["CPASSWORD"].ToString() != "")
                {
                    model.CPASSWORD = ds.Tables[0].Rows[0]["CPASSWORD"].ToString();
                }
                if (ds.Tables[0].Rows[0]["NTYPE"] != null && ds.Tables[0].Rows[0]["NTYPE"].ToString() != "")
                {
                    model.NTYPE = decimal.Parse(ds.Tables[0].Rows[0]["NTYPE"].ToString());
                }
                return model;
            }
            else
            {
                return null;
            }
        }
        #endregion
        #region TB_CHECK
        public bool IsExist(decimal sqdh)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from TB_CHECK");
            strSql.Append(" where SQDH=:SQDH ");
            OracleParameter[] parameters = {
					new OracleParameter(":SQDH", OracleType.Number,10)};
            parameters[0].Value = sqdh;

            return DbHelperOra.Exists(strSql.ToString(), parameters);
        }
        #endregion

        #region TB_YGYXRK_BASE
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public static Model.TB_YGYXRK_BASE Add(Model.TB_YGYXRK_BASE model)
        {
            model.NID = CommonExecute.GetID(model.GetType().Name);

            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into TB_YGYXRK_BASE(");
            strSql.Append("NID,CRWDH,CSQMC,CWXLX,CYXLX,NJS,FMJ,NYPTS,NYPS,DTJSRQ,DTRKRQ,CHSDW,CSMDW,CHSYLX,CCREATEUSER,CBZ)");
            strSql.Append(" values (");
            strSql.Append(":NID,:CRWDH,:CSQMC,:CWXLX,:CYXLX,:NJS,:FMJ,:NYPTS,:NYPS,:DTJSRQ,:DTRKRQ,:CHSDW,:CSMDW,:CHSYLX,:CCREATEUSER,:CBZ)");
            OracleParameter[] parameters = {
					new OracleParameter(":NID", OracleType.Number,10),
					new OracleParameter(":CRWDH", OracleType.NVarChar),
					new OracleParameter(":CWXLX", OracleType.VarChar,100),
					new OracleParameter(":CYXLX", OracleType.NVarChar),
					new OracleParameter(":NJS", OracleType.Number,10),
					new OracleParameter(":FMJ", OracleType.Number,10),
					new OracleParameter(":NYPTS", OracleType.Number,1),
					new OracleParameter(":NYPS", OracleType.Number,10),
					new OracleParameter(":DTJSRQ", OracleType.DateTime),
					new OracleParameter(":DTRKRQ", OracleType.DateTime),
					new OracleParameter(":CHSDW", OracleType.NVarChar),
					new OracleParameter(":CSMDW", OracleType.NVarChar),
					new OracleParameter(":CHSYLX", OracleType.NVarChar),
					new OracleParameter(":CCREATEUSER", OracleType.NVarChar),
					new OracleParameter(":CBZ", OracleType.NVarChar),
                    new OracleParameter(":CSQMC", OracleType.NVarChar)};
            parameters[0].Value = model.NID;
            parameters[1].Value = model.CRWDH;
            parameters[2].Value = model.CWXLX;
            parameters[3].Value = model.CYXLX;
            parameters[4].Value = model.NJS;
            parameters[5].Value = model.FMJ;
            parameters[6].Value = model.NYPTS;
            parameters[7].Value = model.NYPS;
            parameters[8].Value = model.DTJSRQ;
            parameters[9].Value = model.DTRKRQ;
            parameters[10].Value = model.CHSDW;
            parameters[11].Value = model.CSMDW;
            parameters[12].Value = model.CHSYLX;
            parameters[13].Value = model.CCREATEUSER;
            parameters[14].Value = model.CBZ;
            parameters[15].Value = model.CSQMC;

            int rows = DbHelperOra.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return model;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 批量删除数据
        /// </summary>
        public static bool DeleteList(string where)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from TB_YGYXRK_HD ");
            if (!string.IsNullOrEmpty(where))
            {
                strSql.Append(" where " + where);
                int rows = DbHelperOra.ExecuteSql(strSql.ToString());
                if (rows > 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            return false;
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public static Model.TB_YGYXRK_BASE GetModel(decimal NID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select NID,CRWDH,CSQMC,CWXLX,CYXLX,NJS,FMJ,NYPTS,NYPS,DTJSRQ,DTRKRQ,CHSDW,CSMDW,CHSYLX,CCREATEUSER,CBZ from TB_YGYXRK_BASE ");
            strSql.Append(" where NID=:NID ");
            OracleParameter[] parameters = {
					new OracleParameter(":NID", OracleType.Number,22)};

            parameters[0].Value = NID;

            Model.TB_YGYXRK_BASE model = new Model.TB_YGYXRK_BASE();
            DataSet ds = DbHelperOra.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["NID"] != null && ds.Tables[0].Rows[0]["NID"].ToString() != "")
                {
                    model.NID = decimal.Parse(ds.Tables[0].Rows[0]["NID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["CRWDH"] != null && ds.Tables[0].Rows[0]["CRWDH"].ToString() != "")
                {
                    model.CRWDH = ds.Tables[0].Rows[0]["CRWDH"].ToString();
                }
                if (ds.Tables[0].Rows[0]["CSQMC"] != null && ds.Tables[0].Rows[0]["CSQMC"].ToString() != "")
                {
                    model.CSQMC = ds.Tables[0].Rows[0]["CSQMC"].ToString();
                }
                if (ds.Tables[0].Rows[0]["CWXLX"] != null && ds.Tables[0].Rows[0]["CWXLX"].ToString() != "")
                {
                    model.CWXLX = ds.Tables[0].Rows[0]["CWXLX"].ToString();
                }
                if (ds.Tables[0].Rows[0]["CYXLX"] != null && ds.Tables[0].Rows[0]["CYXLX"].ToString() != "")
                {
                    model.CYXLX = ds.Tables[0].Rows[0]["CYXLX"].ToString();
                }
                if (ds.Tables[0].Rows[0]["NJS"] != null && ds.Tables[0].Rows[0]["NJS"].ToString() != "")
                {
                    model.NJS = decimal.Parse(ds.Tables[0].Rows[0]["NJS"].ToString());
                }
                if (ds.Tables[0].Rows[0]["FMJ"] != null && ds.Tables[0].Rows[0]["FMJ"].ToString() != "")
                {
                    model.FMJ = decimal.Parse(ds.Tables[0].Rows[0]["FMJ"].ToString());
                }
                if (ds.Tables[0].Rows[0]["NYPTS"] != null && ds.Tables[0].Rows[0]["NYPTS"].ToString() != "")
                {
                    model.NYPTS = decimal.Parse(ds.Tables[0].Rows[0]["NYPTS"].ToString());
                }
                if (ds.Tables[0].Rows[0]["NYPS"] != null && ds.Tables[0].Rows[0]["NYPS"].ToString() != "")
                {
                    model.NYPS = decimal.Parse(ds.Tables[0].Rows[0]["NYPS"].ToString());
                }
                if (ds.Tables[0].Rows[0]["DTJSRQ"] != null && ds.Tables[0].Rows[0]["DTJSRQ"].ToString() != "")
                {
                    model.DTJSRQ = DateTime.Parse(ds.Tables[0].Rows[0]["DTJSRQ"].ToString());
                }
                if (ds.Tables[0].Rows[0]["DTRKRQ"] != null && ds.Tables[0].Rows[0]["DTRKRQ"].ToString() != "")
                {
                    model.DTRKRQ = DateTime.Parse(ds.Tables[0].Rows[0]["DTRKRQ"].ToString());
                }
                if (ds.Tables[0].Rows[0]["CHSDW"] != null && ds.Tables[0].Rows[0]["CHSDW"].ToString() != "")
                {
                    model.CHSDW = ds.Tables[0].Rows[0]["CHSDW"].ToString();
                }
                if (ds.Tables[0].Rows[0]["CSMDW"] != null && ds.Tables[0].Rows[0]["CSMDW"].ToString() != "")
                {
                    model.CSMDW = ds.Tables[0].Rows[0]["CSMDW"].ToString();
                }
                if (ds.Tables[0].Rows[0]["CHSYLX"] != null && ds.Tables[0].Rows[0]["CHSYLX"].ToString() != "")
                {
                    model.CHSYLX = ds.Tables[0].Rows[0]["CHSYLX"].ToString();
                }
                if (ds.Tables[0].Rows[0]["CCREATEUSER"] != null && ds.Tables[0].Rows[0]["CCREATEUSER"].ToString() != "")
                {
                    model.CCREATEUSER = ds.Tables[0].Rows[0]["CCREATEUSER"].ToString();
                }
                if (ds.Tables[0].Rows[0]["CBZ"] != null && ds.Tables[0].Rows[0]["CBZ"].ToString() != "")
                {
                    model.CBZ = ds.Tables[0].Rows[0]["CBZ"].ToString();
                }
                return model;
            }
            else
            {
                return null;
            }
        }

        public static Model.TB_YGYXRK_BASE GetModel(string CRWDH)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select NID,CRWDH,CSQMC,CWXLX,CYXLX,NJS,FMJ,NYPTS,NYPS,DTJSRQ,DTRKRQ,CHSDW,CSMDW,CHSYLX,CCREATEUSER,CBZ from TB_YGYXRK_BASE ");
            strSql.Append(" where CRWDH=:CRWDH ");
            OracleParameter[] parameters = {
					new OracleParameter(":CRWDH", OracleType.VarChar)};

            parameters[0].Value = CRWDH;

            Model.TB_YGYXRK_BASE model = new Model.TB_YGYXRK_BASE();
            DataSet ds = DbHelperOra.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["NID"] != null && ds.Tables[0].Rows[0]["NID"].ToString() != "")
                {
                    model.NID = decimal.Parse(ds.Tables[0].Rows[0]["NID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["CRWDH"] != null && ds.Tables[0].Rows[0]["CRWDH"].ToString() != "")
                {
                    model.CRWDH = ds.Tables[0].Rows[0]["CRWDH"].ToString();
                }
                if (ds.Tables[0].Rows[0]["CSQMC"] != null && ds.Tables[0].Rows[0]["CSQMC"].ToString() != "")
                {
                    model.CSQMC = ds.Tables[0].Rows[0]["CSQMC"].ToString();
                }
                if (ds.Tables[0].Rows[0]["CWXLX"] != null && ds.Tables[0].Rows[0]["CWXLX"].ToString() != "")
                {
                    model.CWXLX = ds.Tables[0].Rows[0]["CWXLX"].ToString();
                }
                if (ds.Tables[0].Rows[0]["CYXLX"] != null && ds.Tables[0].Rows[0]["CYXLX"].ToString() != "")
                {
                    model.CYXLX = ds.Tables[0].Rows[0]["CYXLX"].ToString();
                }
                if (ds.Tables[0].Rows[0]["NJS"] != null && ds.Tables[0].Rows[0]["NJS"].ToString() != "")
                {
                    model.NJS = decimal.Parse(ds.Tables[0].Rows[0]["NJS"].ToString());
                }
                if (ds.Tables[0].Rows[0]["FMJ"] != null && ds.Tables[0].Rows[0]["FMJ"].ToString() != "")
                {
                    model.FMJ = decimal.Parse(ds.Tables[0].Rows[0]["FMJ"].ToString());
                }
                if (ds.Tables[0].Rows[0]["NYPTS"] != null && ds.Tables[0].Rows[0]["NYPTS"].ToString() != "")
                {
                    model.NYPTS = decimal.Parse(ds.Tables[0].Rows[0]["NYPTS"].ToString());
                }
                if (ds.Tables[0].Rows[0]["NYPS"] != null && ds.Tables[0].Rows[0]["NYPS"].ToString() != "")
                {
                    model.NYPS = decimal.Parse(ds.Tables[0].Rows[0]["NYPS"].ToString());
                }
                if (ds.Tables[0].Rows[0]["DTJSRQ"] != null && ds.Tables[0].Rows[0]["DTJSRQ"].ToString() != "")
                {
                    model.DTJSRQ = DateTime.Parse(ds.Tables[0].Rows[0]["DTJSRQ"].ToString());
                }
                if (ds.Tables[0].Rows[0]["DTRKRQ"] != null && ds.Tables[0].Rows[0]["DTRKRQ"].ToString() != "")
                {
                    model.DTRKRQ = DateTime.Parse(ds.Tables[0].Rows[0]["DTRKRQ"].ToString());
                }
                if (ds.Tables[0].Rows[0]["CHSDW"] != null && ds.Tables[0].Rows[0]["CHSDW"].ToString() != "")
                {
                    model.CHSDW = ds.Tables[0].Rows[0]["CHSDW"].ToString();
                }
                if (ds.Tables[0].Rows[0]["CSMDW"] != null && ds.Tables[0].Rows[0]["CSMDW"].ToString() != "")
                {
                    model.CSMDW = ds.Tables[0].Rows[0]["CSMDW"].ToString();
                }
                if (ds.Tables[0].Rows[0]["CHSYLX"] != null && ds.Tables[0].Rows[0]["CHSYLX"].ToString() != "")
                {
                    model.CHSYLX = ds.Tables[0].Rows[0]["CHSYLX"].ToString();
                }
                if (ds.Tables[0].Rows[0]["CCREATEUSER"] != null && ds.Tables[0].Rows[0]["CCREATEUSER"].ToString() != "")
                {
                    model.CCREATEUSER = ds.Tables[0].Rows[0]["CCREATEUSER"].ToString();
                }
                if (ds.Tables[0].Rows[0]["CBZ"] != null && ds.Tables[0].Rows[0]["CBZ"].ToString() != "")
                {
                    model.CBZ = ds.Tables[0].Rows[0]["CBZ"].ToString();
                }
                return model;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 获取记录数
        /// </summary>
        /// <param name="strWhere"></param>
        /// <returns></returns>
        public static int GetCount(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) num ");
            strSql.Append(" FROM TB_YGYXRK_BASE ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            object obj = DbHelperOra.GetSingle(strSql.ToString());
            return int.Parse(obj.ToString());
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public static DataTable GetList(string strWhere, int startRecord, int maxRecords)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select NID,CSQMC,CRWDH,CWXLX,CYXLX,NJS,FMJ,NYPTS,NYPS,DTJSRQ,DTRKRQ,CHSDW,CSMDW,CHSYLX,CCREATEUSER,CBZ ");
            strSql.Append(" FROM TB_YGYXRK_BASE ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperOra.Query(strSql.ToString(), startRecord, maxRecords);
        }

        #endregion
    }
}
